#pragma once
#include <irrlicht.h>
#include <string>
#include <list>
#include "Timer.h"
#include "CharGenerator.h"

using namespace irr;
using namespace scene;
using namespace video;
using namespace gui;

class CRandom;
class CSerial;

class CGuiEngine : public IEventReceiver, ICharGenObserver
{
public:
	CGuiEngine(void);
	virtual ~CGuiEngine(void);
	void Setup();
	void Run();
	void TearDown();

public: 
	//From IEventReceiver
	virtual bool OnEvent(const SEvent& event);

	//From ICharGenObserver
	virtual void CharEvent(char aChar, unsigned int aIndex);
	virtual void CharGenFinished();

private:
	void LayoutComponents();
	void AddTextWithColor(IGUIStaticText* text);

	void HandleRandomBtn();
	void HandleLockBtn();
	void HandleConnectBtn();
	void HandleSendTextBtn();	

	IGUIElement* GetElement(int aElementId);
	char* GetElementText(int aElementId);
	int GetElementTextAsInt(int aElementId);
	void ToggleElementEnabled(int aElementId);

private:
	IrrlichtDevice* iDevice;
	IVideoDriver* iDriver;
	ISceneManager* iScenemgr;
	
	CTimer* iTimer;
	CRandom* iGen;
	CCharGenerator* iCharGen;
	CSerial* iSerial;

	bool iLocked;
	SColor* iFontColor;
	SColor* iBackgroundColor;
	std::string iLotStr;
	std::list<unsigned int> iLots;
};